package com.centronix.manager.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.centronix.bean.ComboBean;
import com.centronix.dao.ExpenseTypeDAO;
import com.centronix.domain.ExpenseType;
import com.centronix.manager.ExpenseTypeManager;

@Service("ExpenseTypeManager")
@Transactional
public class ExpenseTypeManagerImpl implements ExpenseTypeManager{
	
	private static final long serialVersionUID = 1L;
	
	@Autowired
	private ExpenseTypeDAO expenseTypeDAO;
	
	public List<ComboBean> getProductTypeCombo(){
		List<ComboBean> comboBeans = new ArrayList<>();
		comboBeans.add(ComboBean.getDefaultCombo());
		List<ExpenseType> expenseTypes= expenseTypeDAO.findAll();
		ComboBean comboBean = null;
		for (ExpenseType expenseType : expenseTypes) {
			comboBean = new ComboBean();
			copyExpenseTypeToComboBean(expenseType, comboBean);
			comboBeans.add(comboBean);
		}
		return comboBeans;
	}
	
	public void copyExpenseTypeToComboBean(final ExpenseType expenseType, final ComboBean comboBean) {
		comboBean.setValue(String.valueOf(expenseType.getExpenseTypeId()));
		comboBean.setLabel(expenseType.getNarrative());
	}

	public ExpenseTypeDAO getExpenseTypeDAO() {
		return expenseTypeDAO;
	}

	public void setExpenseTypeDAO(ExpenseTypeDAO expenseTypeDAO) {
		this.expenseTypeDAO = expenseTypeDAO;
	}


}
